import QtQuick 2.5
import QtQuick.Controls 2.1
import ".."

Popup
{
    id: myMessageBox
    width: 1024
    height: 600
    property int type: Common.msgTwoBtn
    property alias title: titleText.text
    property alias content: contentText.text
    property alias btn1Text: btn1.text
    property alias btn2Text: btn2.text
    property alias source: titleIcon.source
    property var callback: null
    background: Rectangle
    {
        color: Qt.rgba(0, 0, 0, 0.1)
    }
    MyRectangle
    {
        height: 300
        width: 400
        radius: 10
        anchors.centerIn: parent

        Image
        {
            id: titleIcon
            anchors.top: parent.top
            anchors.topMargin: 40
            anchors.horizontalCenter: parent.horizontalCenter
            source: "qrc:/Images/msg_notice.png"
        }

        Text
        {
            id: titleText
            anchors.top: titleIcon.bottom
            anchors.topMargin: 20
            anchors.horizontalCenter: parent.horizontalCenter
            font.family: Common.fontMain
            font.pixelSize: 18
            color: Common.colorTextBlack
            text: "这是标题"
        }

        Text
        {
            id: contentText
            anchors.top: titleText.bottom
            anchors.topMargin: 20
            anchors.horizontalCenter: parent.horizontalCenter
            font.family: Common.fontMain
            font.pixelSize: 16
            color: Common.colorText
            text: "这是内容"
        }

        MyButton
        {
            id: btn1
            text: "确定"
            height: 40
            width: 90
            radius: 5
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 20
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.horizontalCenterOffset: myMessageBox.type == Common.msgTwoBtn ? -65 : 0
            onClicked:
            {
                if(myMessageBox.callback != null) myMessageBox.callback(true)
                myMessageBox.close()
            }
        }

        MyButton
        {
            id: btn2
            text: "取消"
            isMain: false
            height: 40
            width: 90
            visible: myMessageBox.type == Common.msgTwoBtn
            anchors.bottom: btn1.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.horizontalCenterOffset: 65
            onClicked:
            {
                if(myMessageBox.callback != null) myMessageBox.callback(false)
                myMessageBox.close()
            }
        }
    }
}
